$(function () {
    //注册账号
    $('#register').click(function () {

        //发送同步ajax请求 获取upwd和nickname
        //设置ajax为同步
        $.ajaxSettings.async = false;
        $.get("/user/" + uname, function (data) {
            upwd = data.data.password;
            nickname = data.data.nickname;
        })
        var options = {
            username: uname,
            password: upwd,
            nickname: nickname,
            appKey: WebIM.config.appkey,
            success: function (res) {
                console.log('注册成功', res)
                alert("注册成功")
            },
            error: function (err) {
                console.log('注册失败', err)
                alert("注册失败")
            },
            apiUrl: WebIM.config.apiURL
        };
        WebIM.conn.registerUser(options);
    })
    //登陆
    $('#login').click(function () {
        uname = $("#name").val();
        //发送同步ajax请求 获取upwd和nickname
        //设置ajax为同步
        $.ajaxSettings.async = false;
        $.get("/user/" + uname, function (data) {
            upwd = data.data.password;
            nickname = data.data.nickname;
        })
        options = {
            apiUrl: WebIM.config.apiURL,
            user: uname,
            pwd: upwd,
            appKey: WebIM.config.appkey
        };
        WebIM.conn.open(options);
    })
    //退出
    $('#logout').click(function () {
        WebIM.conn.close();
    });
})